package com.sxz.sbs.module.photo;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxz.sbs.R;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.base.BasePresenter;

import butterknife.BindView;

/**
 * 图片预览
 * @author hp
 */
public class PhotoViewerActivity extends BaseActivity {
    @BindView(R.id.photo_viewer_index)
    TextView tvIndex;
    @BindView(R.id.photo_viewer_back)
    ImageView ivBack;
    @BindView(R.id.photo_viewer_viewpager)
    ViewPager viewPager;
    public static final String PHOTO_VIEWER_TAG = "PhotoViewerActivity";
    private PhotoViewerAdapter viewerAdapter;
    private PhotoViewerBean photoViewerBean;
    @Override
    protected void init() {
        Intent intent = getIntent();
        photoViewerBean =  intent.getParcelableExtra(PHOTO_VIEWER_TAG);
        if (photoViewerBean != null) {
            final int photoTotal = photoViewerBean.getPhotos().size();
            viewerAdapter = new PhotoViewerAdapter(this,photoViewerBean.getPhotos());
            viewPager.setOffscreenPageLimit(4);
            viewPager.setAdapter(viewerAdapter);
            viewPager.setCurrentItem(photoViewerBean.getPositionIndex());
            tvIndex.setText((photoViewerBean.getPositionIndex()+1)+"/"+ photoTotal);
            viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }
                @Override
                public void onPageSelected(int position) {
                    tvIndex.setText((position+1)+"/"+ photoTotal);

                }
                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });
        }
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_photo_viewer;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
}
